
import {combineReducers} from 'redux'
import {prefix} from './utils'
export default function createReducers(models){
    let reducers = {}
for(let model of models){
    let {namespace,state:initialState,reducers:modelReducers} = model
    let reducersWithPrefix = prefix(modelReducers,namespace) //KEY已经增加了命名空间前缀
    reducers[namespace] = function(state=initialState,action){
        let reducer = reducersWithPrefix[action.type] //type='count/add'
        if(reducer){
            return reducer(state,action)
        } //如果reducer没有匹配上 说明axtion不是给我处理的  直接返回老状态
        return state
    }
}
    return  combineReducers(reducers)
}
